/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.jsontest.record;

import com.tencent.tendon.convert.json.JsonConvert;
import com.tencent.tendon.convert.jsontest.Utility;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author nbzhang
 */
public class GenericTypeRecord {

    private List<Map<Integer, Map<String, Long>[]>> data;

    public static void main(String[] args) throws Throwable {
        GenericTypeRecord record = new GenericTypeRecord();

        Map<Integer, Map<String, Long>[]> map1 = new HashMap();
        map1.put(11, new Map[]{createMapStringLong(111), createMapStringLong(112), createMapStringLong(113)});
        map1.put(12, new Map[]{createMapStringLong(121), createMapStringLong(122), createMapStringLong(133)});


        Map<Integer, Map<String, Long>[]> map2 = new HashMap();
        map2.put(21, new Map[]{createMapStringLong(211), createMapStringLong(212), createMapStringLong(213)});
        map2.put(22, new Map[]{createMapStringLong(221), createMapStringLong(222), createMapStringLong(223)});

        List<Map<Integer, Map<String, Long>[]>> list = new ArrayList();

        list.add(map1);
        list.add(map2);
        record.setData(list);
        String json = JsonConvert.convertTo(record);
        String fast = record.toString();
        String json2 = JsonConvert.convertTo(JsonConvert.convertFrom(json, record.getClass()));
        if (!json.equals(fast) || !json.equals(json2)) {
            System.err.println("GenericTypeRecord error : ");
            System.out.println(json);
            System.out.println(fast);
            System.out.println(json2);
        }
    }

    private static Map<String, Long> createMapStringLong(int index) {
        Map<String, Long> map = new HashMap<String, Long>();
        map.put("name" + index + "_1", index * 10000 + 11L);
        map.put("name" + index + "_2", index * 1000000 + 22L);
        map.put("name" + index + "_3", index * 1000000 + 33L);
        return map;
    }

    @Override
    public String toString() {
        return Utility.listingString(this);
    }

    public List<Map<Integer, Map<String, Long>[]>> getData() {
        return data;
    }

    public void setData(List<Map<Integer, Map<String, Long>[]>> data) {
        this.data = data;
    }
}
